<template>
  <div>
    <form @submit.prevent="add()">
      <div class="mb-3 row">
        <label for="inputPassword" class="col-sm-2 col-form-label">难度</label>
        <div class="col-sm-10">
          <input
            type="text"
            class="form-control"
            v-model="dname"
            required="required"
          />
        </div>
      </div>

      <div class="mb-3 row">
        <label for="inputPassword" class="col-sm-2 col-form-label">分数</label>
        <div class="col-sm-10">
          <input
            type="text"
            class="form-control"
            v-model="score"
            required="required"
          />
        </div>
      </div>

      <button type="submit" class="btn btn-secondary">提交</button>
      &nbsp;&nbsp;&nbsp;
      <router-link to="/difficulty/list" class="btn btn-secondary"
        >返回</router-link
      >
    </form>
  </div>
</template>

<script>
export default {
  name: "DifficultyAdd",
  data() {
    return {
      dname: "",
      score: ""
    };
  },
  methods: {
    add() {
      this.axiosJSON
        .post("/difficulty/add", { dname: this.dname, score: this.score })
        .then((result) => {
          if (result.data.code == 0) {
            this.$message({ type: "success", message: result.data.msg });
            this.$router.push("/difficulty/list"); //编程方式跳转到学科列表组件
          } else {
            this.$message.error(result.data.msg);
          }
        });
    },
  },
  mounted() {
    this.$parent.difficultyTitle = "增加难度"
  },
};
</script>

<style>
</style>
